package com.chuanyang.driverh.mainmy.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chuanyang.driverh.R;
import com.chuanyang.driverh.amap.LocationEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * 地址检索的adapter
 * @author joyskim
 *
 */
public class AddressAdapter extends BaseAdapter{

	private static Context context;
	private List<LocationEntity> addrs=new ArrayList<LocationEntity>();



	public AddressAdapter(Context context, List<LocationEntity> addrs) {
		this.context = context;
		this.addrs = addrs;

	}

	@Override
	public int getCount() {
		return addrs.size();
	}

	public void clear(){
		addrs.clear();
		notifyDataSetChanged();
	}

	//add的集合必须有数据
	public void add(List<LocationEntity> data){
		addrs.addAll(data);
		notifyDataSetChanged();
	}

	@Override
	public Object getItem(int position) {
		return addrs.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder h=null;
		if(convertView==null){
			convertView=View.inflate(context, R.layout.my_item_select_addr_as_input, null);
			h=new ViewHolder();
			h.tvBulding=((TextView)convertView.findViewById(R.id.tv_addr_name));
			h.tvAddress=((TextView)convertView.findViewById(R.id.tv_addr_addr));
			convertView.setTag(h);
		}else{
			h=(ViewHolder) convertView.getTag();
		}

		LocationEntity one = addrs.get(position);
		h.tvBulding.setText(one.getBuilding());
		h.tvAddress.setText(one.getAddress());
		return convertView;
	}

	class ViewHolder{
		TextView tvBulding;
		TextView tvAddress;
	}



}
